home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / IFACE.C < prev    next >
C/C++ Source or Header  |  1989-07-18  |  2KB  |  75 lines

  1. #include "global.h"
  2. #include "iface.h"
  3.  
  4. static char if_unknown[] = "Interface \"%s\" unknown\n";
  5.  
  6. /* find an interface, return pointer or NULLIF on error. print diagnostic. */
  7. struct interface *
  8. ifunit(name)
  9.     char *name;
  10. {
  11.     register struct interface *ifp;
  12.  
  13.     for(ifp=ifaces;ifp != NULLIF;ifp = ifp->next){
  14.         if(strcmp(name,ifp->name) == 0)
  15.             return ifp;;
  16.     }
  17.     printf(if_unknown,name);
  18.     return NULLIF;
  19. }
  20.  
  21. struct interface *
  22. if_lookup(name)
  23. char *name;
  24. {
  25.     register struct interface *iface;
  26.  
  27.     for(iface = ifaces; iface != NULLIF; iface = iface->next)
  28.         if(strcmp(iface->name,name) == 0)
  29.             break;
  30.     return iface;
  31. }
  32. /* Divert output packets from one interface to another. Useful for ARP
  33.  * and digipeat frames coming in from receive-only interfaces
  34.  */
  35. doforward(argc,argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.     struct interface *iface,*iface1;
  40.  
  41.  
  42.     if(argc < 2){
  43.         for(iface = ifaces; iface != NULLIF; iface = iface->next){
  44.             if(iface->forw != NULLIF){
  45.                 printf("%s -> %s\n",iface->name,iface->forw->name);
  46.             }
  47.         }
  48.         return 0;
  49.     }
  50.     if((iface = if_lookup(argv[1])) == NULLIF){
  51.         printf(if_unknown,argv[1]);
  52.         return 1;
  53.     }
  54.     if(argc < 3){
  55.         if(iface->forw == NULLIF)
  56.             printf("%s not forwarded\n",iface->name);
  57.         else
  58.             printf("%s -> %s\n",iface->name,iface->forw->name);
  59.         return 0;
  60.     }
  61.     if((iface1 = if_lookup(argv[2])) == NULLIF){
  62.         printf(if_unknown,argv[2]);
  63.         return 1;
  64.     }
  65.     if(iface1 == iface){
  66.         /* Forward to self means "turn forwarding off" */
  67.         iface->forw = NULLIF;
  68.     } else {
  69.         if(iface1->output != iface->output)
  70.             printf("Warning: Interfaces of different type\n");
  71.         iface->forw = iface1;
  72.     }
  73.     return 0;
  74. }
  75.